package com.io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;

/**
 * 标准输入输出重定向
 * 
 * @author Administrator
 * 
 */
public class Redirecting {

	public static void main(String[] args) throws IOException {
		PrintStream console = System.out;// 存储了对最初的System.out对象的引用，并且在结尾处将系统输出恢复到该对象上
		BufferedInputStream in = new BufferedInputStream(new FileInputStream(
				"c:/aa.txt"));
		PrintStream out = new PrintStream(new BufferedOutputStream(
				new FileOutputStream("c:/bb.txt")));

		System.setIn(in);// 标准输入定位到aa.txt
		System.setOut(out);// 标准输出定位到bb.txt
		System.setErr(out);

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s;
		while ((s = br.readLine()) != null) {
			System.out.println(s);
		}
		out.close();
		System.setOut(console);
		System.out.println("aaaaaaa");
	}

}
